#!/bin/ksh

echo "Please input the DATE of Every Thursday!!"
echo "The Date format is: yyyymmdd"
echo "Press enter directly is to show Last Thursday's Backup logs"
read MYDATE

TEST=mytest$MYDATE

MYYEAR=`expr substr "$MYDATE" 3 4` 
MYMONTH=`expr substr "$MYDATE" 5 2` 
MYDAY=`expr substr "$MYDATE" 7 2` 

diff=`date +%u`

if [ $diff -gt 4 ]
then
  dayago=`expr $diff - 4`
else
  dayago=`expr $diff + 3`
fi


if [ $TEST = mytest ];then
  Serach_date=`date +%Y -d "$dayago day ago"`/`date +%m -d "$dayago day ago"`/`date +%d -d "$dayago day ago"`
else 
  Serach_date=${MYYEAR}/${MYMONTH}/${MYDAY}
fi
LOG=/oracle/newbackup/log/joblog_`date +%Y%m`.log
grep "^$Serach_date" $LOG > /tmp/back.log
TEST1=`grep -c "Start_APP NORMAL END" /tmp/back.log`
if [ $TEST1 -gt 0 ]
then
  echo "                                      "
  echo " ******** Backup Sucessfully ******** "
  echo "                                      "
  echo " The Detail Information as  following "
  echo "                                      "
  LineBegin=`sed -n '/Stop_APP START/=' /tmp/back.log`
  LineEnd=`sed -n '/Start_APP NORMAL END/=' /tmp/back.log`
  sed -n "${LineBegin},${LineEnd}p" /tmp/back.log 
else
  echo "                                      "
  echo " ****** Backup May Have Error  ****** "
  echo " ****  Or Backup Is Running now ***** "
  echo "                                      "
  echo "                                      "
  echo "****** Do You Want To See Detail ********"
  echo "****** Press Yes(y) to See Detail *******"
  read MYYES
  case  $MYYES in
    Y|y)cat  /tmp/back.log
        echo 
	echo
    ;;
    *) exit
    ;;
   esac 
fi
rm /tmp/back.log

